/*
 * @Author       : Deng
 * @Date         : 2024-05-02 00:12:04
 * @LastEditors  : Joel
 * @LastEditTime : 2024-05-08 08:03:29
 * @FilePath     : \src\desmos.c
 * @Description  :
 * Copyright 2024 YiJiaLink, All Rights Reserved.
 * 2024-05-02 00:12:04
 */
#include "desmos.h"
uint8_t red_data[PWM_CYCLE];
uint8_t green_data[PWM_CYCLE];
uint8_t blue_data[PWM_CYCLE];
uint8_t white_data[PWM_CYCLE];
static uint8_t flag;
init_rgb_pwm set_rgb_pwm, *p_pwm;
float get_apm_value(uint16_t time, uint16_t b,uint8_t flag)
{
	float index, value, data;

	index = (float)(2 * PI * time);
	value = (float)(index / b);
	if(flag)
	data = cosf(value);
	else
	data = sinf(value);
	/* 绝对值 */
	return (fabsf(255 * data));
}
void rgb_duty_run(void)
{
	p_pwm = &set_rgb_pwm;
	p_pwm->white_duty = PWM_CYCLE;
	printf("x=[");
	for (uint32_t i = 0; i < PWM_CYCLE * 4; i++)
		printf("%d,", i);
	printf("]\r\n");
	flag = 1;
	while (flag)
	{
		/* code */
		switch (p_pwm->brightness_index)
		{
		case RED /* constant-expression */:
			/* code */
			if (PWM_CYCLE == p_pwm->red_duty)
			{

				p_pwm->brightness_index++;
				printf("red=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", red_data[i]);
				printf("]\r\n");
				printf("green=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", green_data[i]);
				printf("]\r\n");
				printf("blue=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", blue_data[i]);
				printf("]\r\n");
				printf("white=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", white_data[i]);
				printf("]\r\n");
			}
			else
			{
				++p_pwm->red_duty;
				--p_pwm->white_duty;
			}
			red_data[p_pwm->red_duty - 1] = p_pwm->red_duty;
			green_data[p_pwm->red_duty - 1] = p_pwm->green_duty;
			blue_data[p_pwm->red_duty - 1] = p_pwm->blue_duty;
			white_data[p_pwm->red_duty - 1] = p_pwm->white_duty;
			break;
		case GREEN /* constant-expression */:
			/* code */
			if (PWM_CYCLE == p_pwm->green_duty)
			{
				p_pwm->brightness_index++;
				printf("red=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", red_data[i]);
				printf("]\r\n");
				printf("green=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", green_data[i]);
				printf("]\r\n");
				printf("blue=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", blue_data[i]);
				printf("]\r\n");
				printf("white=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", white_data[i]);
				printf("]\r\n");
			}
			else
			{
				++p_pwm->green_duty;
				--p_pwm->red_duty;
			}
			red_data[p_pwm->green_duty - 1] = p_pwm->red_duty;
			green_data[p_pwm->green_duty - 1] = p_pwm->green_duty;
			blue_data[p_pwm->green_duty - 1] = p_pwm->blue_duty;
			white_data[p_pwm->green_duty - 1] = p_pwm->white_duty;
			break;
		case BLUE /* constant-expression */:
			/* code */
			if (PWM_CYCLE == p_pwm->blue_duty)
			{
				p_pwm->brightness_index++;
				printf("red=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", red_data[i]);
				printf("]\r\n");
				printf("green=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", green_data[i]);
				printf("]\r\n");
				printf("blue=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", blue_data[i]);
				printf("]\r\n");
				printf("white=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", white_data[i]);
				printf("]\r\n");
			}
			else
			{
				++p_pwm->blue_duty;
				--p_pwm->green_duty;
			}
			red_data[p_pwm->blue_duty - 1] = p_pwm->red_duty;
			green_data[p_pwm->blue_duty - 1] = p_pwm->green_duty;
			blue_data[p_pwm->blue_duty - 1] = p_pwm->blue_duty;
			white_data[p_pwm->blue_duty - 1] = p_pwm->white_duty;
			break;
		case WHITE /* constant-expression */:
			/* code */
			if ((PWM_CYCLE) == p_pwm->white_duty)
			{
				p_pwm->brightness_index++;
				printf("]\r\n");
				printf("red=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", red_data[i]);
				printf("]\r\n");
				printf("green=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", green_data[i]);
				printf("]\r\n");
				printf("blue=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", blue_data[i]);
				printf("]\r\n");
				printf("white=[");
				for (uint8_t i = 0; i < 255; i++)
					printf("%d,", white_data[i]);
				printf("]\r\n");
				flag = 0;
			}
			else
			{
				++p_pwm->white_duty;
				--p_pwm->blue_duty;
			}
			red_data[p_pwm->white_duty - 1] = p_pwm->red_duty;
			green_data[p_pwm->white_duty - 1] = p_pwm->green_duty;
			blue_data[p_pwm->white_duty - 1] = p_pwm->blue_duty;
			white_data[p_pwm->white_duty - 1] = p_pwm->white_duty;
			break;
		default:
			flag = 0;
			break;
		}
	}
}